package com.ztools.wx.controller;

import com.ztools.common.util.common.Result;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author:seeTools
 * @Date: 2023/4/8  21:27
 * @Version 1.0
 */
@RestController
public class WxJsapiController {

    @Resource
    private WxMpService wxMpService;

    @PostMapping("/jsapiSignature")
    public Result jsapiSignature(String url) {
        try {
            WxJsapiSignature jsapiSignature = wxMpService.createJsapiSignature(url);
            return Result.success().data(jsapiSignature);
        } catch (WxErrorException e) {
            e.printStackTrace();
        }
        return Result.error("获取jsapi签名失败");
    }
}
